package com.hangxiang.approval.controller;

import com.hangxiang.approval.common.*;
import com.hangxiang.approval.entity.User;
import com.hangxiang.approval.enums.ResultStatusEnum;
import com.hangxiang.approval.service.UserService;
import com.hangxiang.approval.vo.UserPageVo;
import com.hangxiang.approval.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户表(User)表控制层
 *
 * @author makejava
 * @since 2020-11-23 16:29:56
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户表User相关功能")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param common 主键
     * @return 单条数据
     */
    @PostMapping("selectOne")
    @ApiOperation(value = "通过主键查询单条数据")
    @ResponseBody
    public ResultBean<UserVo> selectOne(@RequestBody @Validated IntegerCommon common) {
        return ResultBean.success(userService.queryById(common));
    }


    /**
     * 通过主键查询所有数据
     *
     * @param common 主键
     * @return
     */
    @PostMapping("selectAllInfo")
    @ApiOperation(value = "通过分页和模糊搜索查询数据")
    @ResponseBody
    public ResultBean selectAllInfo(@RequestBody @Validated UserPageCommon common) {
        return ResultBean.success(userService.selectAllInfo(common));
    }

    @PostMapping("selectUser")
    @ApiOperation(value = "通过分页查询所有用户")
    @ResponseBody
    public ResultBean selectUser(@RequestBody @Validated UserPageCommon common) {
        return ResultBean.success(userService.selectUserInfo(common));
    }

    /**
     * 新增数据
     *
     * @param userInsertCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("insertUser")
    @ApiOperation(value = "添加数据")
    @ResponseBody
    public ResultBean insert(@RequestBody @Validated UserInsertCommon userInsertCommon) {
        return ResultBean.success(userService.insertUser(userInsertCommon));
    }

    /**
     * 新增数据
     *
     * @param userUpdateCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("updateUser")
    @ApiOperation(value = "修改数据")
    @ResponseBody
    public ResultBean update(@RequestBody @Validated UserUpdateCommon userUpdateCommon) {
        return ResultBean.success(userService.updateUser(userUpdateCommon));
    }

    @PostMapping("userLogin")
    @ApiOperation(value = "用户登录")
    @ResponseBody
    public ResultBean<UserVo> userLogin(@RequestBody @Validated UserLoginCommon common) {
        UserVo userVo = userService.userLogin(common);
        return ResultBean.success(userVo);
    }




}